package utils;

import lombok.Data;
import lombok.ToString;

/**
 * @author Allen_HJL
 * @version 1.0
 * @date 2020/9/13 9:34
 */
@Data
@ToString
public class ResponseBean {

    private Integer code;
    private String message;
    private Object data;

    public ResponseBean(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseBean(Integer code, String message) {
        this.code = code;
        this.message = message;

    }

    public ResponseBean(ResultCode resultCode, Object data) {
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }

    public ResponseBean(ResultCode resultCode) {
        this.code = resultCode.code();
        this.message = resultCode.message();

    }

    public ResponseBean() {
    }

    /**
     * 返回成功
     */
    public static ResponseBean success() {
        ResponseBean respBean = new ResponseBean(ResultCode.SUCCESS);
        return respBean;
    }

    public static ResponseBean success(ResultCode code) {
        ResponseBean respBean = new ResponseBean(code);
        return respBean;
    }

    public static ResponseBean success(ResultCode code, Object data) {
        ResponseBean respBean = new ResponseBean(code);
        respBean.setData(data);
        return respBean;
    }

    public static ResponseBean success(Object data) {
        ResponseBean respBean = new ResponseBean(ResultCode.SUCCESS);
        respBean.setData(data);
        return respBean;
    }

    /**
     * 返回失败
     **/
    public static ResponseBean failure(ResultCode resultCode) {
        ResponseBean respBean = new ResponseBean(resultCode);
        return respBean;
    }

    public static ResponseBean failure(ResultCode resultCode, Object data) {
        ResponseBean respBean = new ResponseBean(resultCode);
        respBean.setData(data);
        return respBean;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
